package com.chinda.common.aspect;

import com.chinda.common.config.properties.CacheProperties;
import com.chinda.common.exception.RRException;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * @author Wang Chinda
 * @date 2021/7/22
 * @see
 * @since 1.0
 */
@Slf4j
@Aspect
@Component
@AllArgsConstructor
public class CacheAspect {

    private final CacheProperties cacheProperties;

    @Around("execution(* com.chinda.common.utils.RedisUtil.*(..))")
    public Object around(ProceedingJoinPoint point) throws Throwable {
        Object result = null;
        if(cacheProperties.isRedis()){
            try{
                result = point.proceed();
            }catch (Exception e){
                log.error("redis error", e);
                throw new RRException("Redis服务异常");
            }
        }
        return result;
    }
}
